home *** CD-ROM | disk | FTP | other *** search
/ Interactive Media Design Review 1999 / Interactive Media Design Review 1999.iso / pc / Demos / Herois / Codigo.Cst / 00024_Script_Texto Scroll por Sensibilidade 2 < prev    next >
Text File  |  1999-03-19  |  7KB  |  254 lines

  1. property spr, mem, spr2, mem2
  2. property interessados
  3. property velMax, velMin, puloMax
  4. property linhaAtual, linhaMax
  5. property numLinhas
  6. property alturaLinha, linhasJanela
  7. property numLinhas2
  8. property ultimoScroll, lastOut
  9. property areaSensivel
  10. property ligado, modificouCursor
  11. property numCursor
  12. property scrolou
  13.  
  14. on getPropertyDescriptionList
  15.   set p_list = [ ¼
  16.     #alturaLinha: [ #comment: "Altura (em pixels) de cada linha (0 p/ nao alterar)", ¼
  17.                #format:  #integer,¼
  18.                #default: 16 ],¼
  19.     #velMax: [ #comment: "Velocidade maxima(pix/s)", ¼
  20.                #format:  #integer,¼
  21.                #default: 96 ],¼
  22.     #velMin: [ #comment: "Velocidade minima(pix/s)", ¼
  23.                #format:  #integer,¼
  24.                #default: 16 ],¼
  25.     #puloMax: [ #comment: "Maior pulo do scroll (em pixels)", ¼
  26.                #format:  #integer,¼
  27.                #default: 16 ],¼
  28.     #interessados: [ #comment: "Sprites que se interessam pelo scroll:", ¼
  29.                #format:   #list, ¼
  30.                #default: [] ],¼
  31.     #areaSensivel: [ #comment: "Area sensivel (em pixels)", ¼
  32.                #format:  #integer,¼
  33.                #default: 48 ]¼
  34.   ]
  35.   return p_list
  36. end
  37.  
  38. on beginSprite me
  39.   set spr = the spriteNum of me
  40.   set spr2 = spr + 1
  41.   set mem = the member of sprite spr
  42.   set mem2 = the member of sprite spr2
  43.   set linhaAtual = 0
  44.   set numLinhas = the lineCount of member mem
  45.   set numLinhas2 = the lineCount of member mem2
  46.   if alturaLinha = 0 then
  47.     set alturaLinha =  lineheight(mem, 1)
  48.   else
  49.     set the lineHeight of member mem to alturaLinha
  50.     set the lineHeight of member mem2 to alturaLinha
  51.   end if
  52.   set linhasJanela = the height of sprite spr / alturaLinha
  53.   set linhaMax = numLinhas + numLinhas2 - 10
  54.   if linhaMax < 0 then set linhaMax = 0
  55.   set linhaMax = linhaMax * alturaLinha
  56.   set the locV of sprite spr to 50
  57.   set the locV of sprite spr2 to 50 + numLinhas * alturaLinha
  58.   set ultimoScroll = the timer
  59.   set lastOut = true
  60.   --  set the visibility of sprite spr to false
  61.   --  set ligado = false
  62.   set modificouCursor = false
  63.   set numCursor = 1
  64. end
  65.  
  66. on idleSprite me
  67.   if not the visible of sprite spr then return
  68.   
  69.   global gMustUpdate
  70.   
  71.   --  if not ligado then
  72.   --    set the visibility of sprite spr to true
  73.   --    set ligado = true
  74.   --    set gMustUpdate = true
  75.   --  end if
  76.   
  77.   -- Verifica se mouse passa por cima do texto
  78.   global gCritico
  79.   set mh = the mouseH
  80.   set mv = the mouseV
  81.   set m = point(mh,mv)
  82.   if not inside(m,rect(30,50,310,430)) or gCritico > 0 then
  83.     set lastOut = true
  84.     if modificouCursor then 
  85.       cursor -1
  86.       set modificouCursor = false
  87.     end if
  88.     return
  89.   end if
  90.   
  91.   
  92.   global gCritico, gMustUpdate
  93.   set y = the mouseV
  94.   
  95.   -- Calcula velocidade conforme posicao do mouse
  96.   set v = 0
  97.   set y = y - 50
  98.   if (y < areaSensivel) then 
  99.     set v = -( (areaSensivel - y) * (velMax - velMin) / areaSensivel + velMin )
  100.   else 
  101.     set y = 380 - y
  102.     if (y < areaSensivel) then
  103.       set v = (areaSensivel - y) * (velMax - velMin) / areaSensivel + velMin
  104.     end if
  105.   end if
  106.   if v = 0 then 
  107.     if not lastOut then set lastOut = true
  108.     if modificouCursor then 
  109.       cursor -1
  110.       set modificouCursor = false
  111.     end if
  112.     return
  113.   end if  
  114.   
  115.   -- Calcula delta de linhas
  116.   if lastOut then
  117.     set lastOut = false
  118.     set ultimoScroll = the timer
  119.     return
  120.   end if
  121.   set dl = (the timer - ultimoScroll) * v / 60
  122.   if dl > 0 and linhaAtual = linhaMax then set dl = 0
  123.   else if dl < 0 and linhaAtual = 0 then set dl = 0
  124.   
  125.   if dl = 0 then 
  126.     if modificouCursor then 
  127.       cursor -1
  128.       set modificouCursor = false
  129.     end if
  130.     return
  131.   end if
  132.   
  133.   if dl > 0 then 
  134.     cursor [the number of member ("CursorBaixo" & numCursor),¼
  135.             the number of member "CursorMask"]
  136.     set numCursor = 3 - numCursor
  137.     set modificouCursor = true
  138.     if dl > puloMax then 
  139.       set dl = puloMax
  140.     end if
  141.   else
  142.     cursor [the number of member ("CursorCima" & numCursor),¼
  143.             the number of member "CursorMask"]
  144.     set numCursor = 3 - numCursor
  145.     set modificouCursor = true
  146.     if dl < - puloMax then
  147.       set dl = - puloMax
  148.     end if
  149.   end if
  150.   set ultimoScroll = the timer
  151.   
  152.   -- Calcula nova linha
  153.   set l = linhaAtual + dl
  154.   if l < 0 then set l = 0
  155.   else if l > linhaMax then
  156.     set dl = dl + linhaMax
  157.     set l = linhaMax
  158.   end if
  159.   
  160.   if l <> linhaAtual then
  161.     set the locV of sprite spr to 50 - l
  162.     set the locV of sprite spr2 to 50 - l +  numLinhas * alturaLinha 
  163.     set gMustUpdate = true
  164.     repeat with i = 1 to count(interessados)
  165.       sendSprite(getAt(interessados,i), #scrollLinha, l - linhaAtual)
  166.     end repeat
  167.     set linhaAtual = l
  168.   end if
  169. end
  170.  
  171. on mouseUp me
  172.   set y = the mouseV
  173.   set dl = 0
  174.   
  175.   -- Calcula velocidade conforme posicao do mouse
  176.   set y = y - 50
  177.   if (y < areaSensivel and linhaAtual > 0) then 
  178.     puppetSound 2, "Warp1"
  179.     -- Scroll page down
  180.     set dl = - 300
  181.   else 
  182.     set y = 380 - y
  183.     if (y < areaSensivel and linhaAtual < linhaMax) then
  184.       puppetSound 2, "Warp2"
  185.       -- Scroll page up
  186.       set dl = + 300
  187.     end if
  188.   end if
  189.   
  190.   if dl = 0 then return
  191.   
  192.   -- Calcula nova linha
  193.   set l = linhaAtual + dl
  194.   if l < 0 then set l = 0
  195.   else if l > linhaMax then
  196.     set l = linhaMax
  197.   end if
  198.   
  199.   if l <> linhaAtual then
  200.     set the locV of sprite spr to 50 - l
  201.     set the locV of sprite spr2 to 50 - l +  numLinhas * alturaLinha 
  202.     repeat with i = 1 to count(interessados)
  203.       sendSprite(getAt(interessados,i), #scrollLinha, l - linhaAtual)
  204.     end repeat
  205.     set linhaAtual = l
  206.   end if
  207.   
  208.   updateStage
  209.   
  210.   stopEvent
  211. end
  212.  
  213. -- Para clicks de scroll de pagina de fora
  214. on tentaScroll me
  215.   set scrolou = false
  216.   set y = the mouseV
  217.   set dl = 0
  218.   
  219.   -- Calcula velocidade conforme posicao do mouse
  220.   set y = y - 50
  221.   if (y < areaSensivel and linhaAtual > 0) then 
  222.     puppetSound 2, "Warp1"
  223.     -- Scroll page down
  224.     set dl = - 300
  225.   else 
  226.     set y = 380 - y
  227.     if (y < areaSensivel and linhaAtual < linhaMax) then
  228.       puppetSound 2, "Warp2"
  229.       -- Scroll page up
  230.       set dl = + 300
  231.     end if
  232.   end if
  233.   
  234.   if dl = 0 then return
  235.   
  236.   -- Calcula nova linha
  237.   set l = linhaAtual + dl
  238.   if l < 0 then set l = 0
  239.   else if l > linhaMax then
  240.     set l = linhaMax
  241.   end if
  242.   
  243.   if l <> linhaAtual then
  244.     set the locV of sprite spr to 50 - l
  245.     set the locV of sprite spr2 to 50 - l +  numLinhas * alturaLinha 
  246.     repeat with i = 1 to count(interessados)
  247.       sendSprite(getAt(interessados,i), #scrollLinha, l - linhaAtual)
  248.     end repeat
  249.     set linhaAtual = l
  250.   end if
  251.   
  252.   updateStage
  253.   set scrolou = true
  254. end